//package com.jyhs.maven.dao.impl;
//
//import com.jyhs.maven.dao.BaseDao;
//import com.jyhs.maven.dao.TransferDao;
//import com.jyhs.maven.util.ReflectUtil;
//import com.jyhs.maven.entity.Transfer;
//import com.jyhs.maven.entity.dto.TransferRecord;
//import com.jyhs.maven.entity.dto.TransferRecordQuery;
//import org.springframework.stereotype.Component;
//import org.springframework.stereotype.Repository;
//
//
//import java.sql.PreparedStatement;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//import java.text.ParseException;
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.List;
//
////@Repository
//public class TransferDaoImpl extends BaseDao implements TransferDao {
//    @Override
//    public int saveTransfer(Transfer transfer) throws SQLException, ClassNotFoundException {
//        //1.增加转账记录
//        String sql="INSERT INTO `transfer` ( `payUserId`, `reciveUserId`, `balance`) VALUES ( ?,?,?)";
//        getUpdate(sql,transfer.getPayUserId(),transfer.getReciveUserId(),transfer.getBalance());
//
//        //2.扣减 转账人 余额
//        String updateSql = "update  user set   balance= balance-?  where id = ? ";
//        getUpdate(updateSql,transfer.getBalance(),transfer.getPayUserId());
//
//        //3.增加 收款人 余额
//        String updateSql2 = "update  user set   balance= balance+?  where id = ? ";
//        getUpdate(updateSql2,transfer.getBalance(),transfer.getReciveUserId());
//        return 1;
//    }
//
//    @Override
//    public List<TransferRecord> getTransferListByPayUserId(String payUserId, String receviId) throws SQLException, ClassNotFoundException {
//        return Collections.emptyList();
//    }
//
//    @Override
//    public List<TransferRecord> getTransferList(TransferRecordQuery query) throws SQLException, ClassNotFoundException, ParseException, IllegalAccessException {
////        String sql="SELECT t1.id,t2.`name` as payName,t3.`name` ReciveName,t3.cardNumber,t1.payTime,t1.balance " +
////                " from transfer t1 " +
////                " left join  user t2  on t1.payUserId = t2.id " +
////                " left join  user t3  on t1.reciveUserId = t3.id " +
////                "WHERE 1=1 order by payTime desc LIMIT ?,?";
//        StringBuilder sb = new StringBuilder("");
//        sb.append("SELECT t1.id,t2.`name` as payName,t3.`name` ReciveName,t3.cardNumber,left(t1.payTime,19) payTime,t1.balance ")
//                .append(" from transfer t1 ")
//                .append(" left join  user t2  on t1.payUserId = t2.id ")
//                .append(" left join  user t3  on t1.reciveUserId = t3.id where 1=1 ");
//
//        List<Object> params = new ArrayList<>();
//        if (query.getPayName()!=null && !"".equals(query.getPayName())){
//           sb.append(" and t2.`name` like ?");
//           params.add("%"+query.getPayName()+"%");
//        }
//        if(query.getRevciveId()!=null ){
//            sb.append(" and t1.reciveUserId = ?");
//            params.add(query.getRevciveId());
//        }
//        if(query.getPayTime()!=null){
//            sb.append(" and left(t1.payTime,10)= ?");
//            params.add(query.getPayTime());
//        }
//        sb.append(" order by payTime desc LIMIT ?,?");
//        Integer page = Integer.parseInt(query.getPage());
//        Integer limit = Integer.parseInt(query.getLimit());
//
//
//        int start = (page- 1) * limit;
//        int end = limit;
//        params.add(start);
//        params.add(end);
//        ResultSet resultSet = getSelect(sb.toString(), params.toArray());
//
//
//        List<TransferRecord> transfers= new ArrayList<>();
//        while (resultSet.next()){
//
//            TransferRecord transfer = new TransferRecord();
//
//            ReflectUtil.resultSetToObject(resultSet,transfer);
////            transfer.setId(resultSet.getLong("id"));
////            transfer.setPayTime(resultSet.getDate("payTime"));
////            transfer.setPayUserId(resultSet.getLong("payUserId"));
////            transfer.setReciveUserId(resultSet.getLong("reciveUserId"));
////            transfer.setBalance(resultSet.getBigDecimal("balance"));
//            transfers.add(transfer);
//        }
//        close(conn,ps,resultSet);
//        return transfers;
//    }
//
//    @Override
//    public int getTransferCount(TransferRecordQuery query) throws SQLException, ClassNotFoundException {
////        int i = 10/0;
////        String sql="SELECT COUNT(*) count FROM `bank`.`transfer`";
//        StringBuilder sb = new StringBuilder("");
//        sb.append("SELECT COUNT(*) count ")
//                .append(" from transfer t1 ")
//                .append(" left join  user t2  on t1.payUserId = t2.id ")
//                .append(" left join  user t3  on t1.reciveUserId = t3.id where 1=1 ");
//        List<Object> params = new ArrayList<>();
//        if (query.getPayName()!=null && !"".equals(query.getPayName())){
//            sb.append(" and t2.`name` like ?");
//            params.add("%"+query.getPayName()+"%");
//        }
//        if(query.getRevciveId()!=null ){
//            sb.append(" and t1.reciveUserId = ?");
//            params.add(query.getRevciveId());
//        }
//        if(query.getPayTime()!=null){
//            sb.append(" and left(t1.payTime,10)= ?");
//            params.add(query.getPayTime());
//        }
//        System.out.println("获取转账记录数量");
//        ResultSet resultSet = getSelect(sb.toString(),params.toArray());
//        if (resultSet.next()){
//            return resultSet.getInt("count");
//        }
//
//        return 0;
//    }
//}
